import { PageVO, TableConfigVO, VueObject } from '@/common/vo';
import { Vue } from 'vue-property-decorator';
import XEUtils from 'xe-utils';

export class BaseCheck extends Vue {
    // columnUtil: any = new CentralSupervisionColumnUtil();

    layoutTableName: string = ''; // 页面布局名

    requestTableMethodName: any = null; // 表格请求方法名

    loadOutRequestName: any = null; // 导出请求名

    layoutDialog: boolean = false; // 布局显示值

    selectedFieldList: any[] = []; // 已选字段

    showColumns: any[] = []; // 展示字段

    tableKey: number = -1; // 表格渲染key

    fixedColumns: any[] = []; // 固定字段

    paging: PageVO = {
        currentPage: 1,
        pageSize: 25,
        total: 0,
    };
    tableLoading: boolean = false;

    tableConfig: TableConfigVO = {
        rowKey: 'fundCode',
    };
    tableColumns: any = [];

    searchParam: any = {};

    tableData: any[] = [];
    checkedRowKeys: any = [];
    isFirst: boolean = true;
    // 个性化
    closeVisible: boolean = false;
    closeReason: string = ''; // 关闭原因

    watchShowColumns() {
        this.$watch(
            () => {
                return (this.$refs['risk-table-layout'] as VueObject).showColumns;
            },
            val => {
                this.showColumns = val && val.length ? val : this.tableColumns;
                this.tableKey++;
            }
        );
    }

    /**
     * 表格数据
     */
    getTableData() {
        this.tableLoading = true;
        return new Promise((resolve, reject) => {
            this.requestTableMethodName({
                ...this.searchParam,
                paging: this.paging,
            })
                .then((res: any) => {
                    this.tableData = res.list || [];
                    this.paging.total = res.total;
                    this.tableLoading = false;
                    resolve(res);
                })
                .catch(err => {
                    this.tableLoading = false;
                    reject(err);
                });
        });
    }

    /**
     * 查询条件回调
     */
    comReturn(obj) {
        this.searchParam = obj?.searchParam;
    }

    /**
     * 筛选分页
     */
    pageRet() {
        this.getTableData();
    }

    /**
     * 操作行回调函数
     */
    async handleButtonEmit(type) {
        // if (type == 'start' || type == 'delete') {
        //     let name = '';
        //     let requestName;
        //     if (type == 'start') {
        //         name = '发起';
        //         requestName = TransfiniteAPI.reportLaunch;
        //     } else if (type == 'delete') {
        //         name = '删除';
        //         requestName = TransfiniteAPI.reportDelete;
        //     }
        //     const checkRowKeys = (this.$refs['risk-table-' + this.type] as VueObject).checkRowKeys;
        //     if (checkRowKeys.length < 1) {
        //         this.yh_message_info(`请先勾选需${name}的数据！`);
        //         return;
        //     }
        //     requestName({ overrunEventIds: checkRowKeys }).then(() => {
        //         this.yh_message_success(name + '成功');
        //         this.paging.currentPage = 1;
        //         this.getTableData();
        //         // 清除导出时列表勾选项
        //         this.$nextTick(() => {
        //             (this.$refs['risk-table-' + this.type] as any).resetCheckRowKeys();
        //         });
        //     });
        // } else if (type == 'close') {
        //     const name = '关闭';
        //     const checkRowKeys = (this.$refs['risk-table-' + this.type] as VueObject).checkRowKeys;
        //     if (checkRowKeys.length < 1) {
        //         this.yh_message_info(`请先勾选需${name}的数据！`);
        //         return;
        //     }
        //     this.closeVisible = true;
        //     this.closeReason = '';
        // } else if (type == 'close-confirm') {
        //     const name = '关闭';
        //     const requestName = TransfiniteAPI.reportClose;
        //     const checkRowKeys = (this.$refs['risk-table-' + this.type] as VueObject).checkRowKeys;
        //     requestName({ overrunEventIds: checkRowKeys, closeReason: this.closeReason }).then(() => {
        //         this.yh_message_success(name + '成功');
        //         this.closeVisible = false;
        //         this.paging.currentPage = 1;
        //         this.getTableData();
        //         // 清除导出时列表勾选项
        //         this.$nextTick(() => {
        //             (this.$refs['risk-table-' + this.type] as any).resetCheckRowKeys();
        //         });
        //     });
        // } else
        if (type == 'search') {
            this.paging.currentPage = 1;
            this.pageRet();
        } else if (type == 'refresh') {
            this.paging.currentPage = 1;
            await this.getTableData();
            this.yh_message_success('刷新成功！');
        } else if (type == 'doLayout') {
            this.layoutDialog = true;
        } else if (type == 'loadout') {
            console.log(this.checkedRowKeys, 'che');
            const data = this.checkedRowKeys.length ? { overrunEventIdList: this.checkedRowKeys } : this.searchParam;
            // 勾选项导出;无勾选,导出全部
            this.loadOutRequestName(data);
            // 清除导出时列表勾选项
            this.$nextTick(() => {
                (this.$refs['risk-table'] as any).resetCheckRowKeys();
            });
        }
    }

    /**
     * 勾选值变化回调
     */
    checkRowKeysChangeEmit(keys: any) {
        this.checkedRowKeys = keys;
    }
}
